load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_cc//cc:defs.bzl", "cc_library")

package(default_visibility = ["//visibility:public"])

string_flag(
    name = "ssl",
    build_setting_default = "no_ssl",
    values = [
        "no_ssl",
        "openssl",
        "boringssl",
    ],
    visibility = ["//visibility:public"],
)

config_setting(
    name = "no_ssl",
    flag_values = {":ssl": "no_ssl"},
)

config_setting(
    name = "openssl",
    flag_values = {":ssl": "openssl"},
)

config_setting(
    name = "boringssl",
    flag_values = {":ssl": "boringssl"},
)

write_file(
    name = "src",
    out = "boost.mysql.src.cpp",
    content = ["#include <boost/mysql/src.hpp>"],
    visibility = ["//visibility:private"],
)

cc_library(
    name = "boost.mysql",
    srcs = [":src"],
    defines = ["BOOST_MYSQL_SEPARATE_COMPILATION"],
    features = [
        "parse_headers",
    ],
    includes = ["include"],
    textual_hdrs = glob([
        "include/**/*.*pp",
    ]),
    deps = [
        "@boost.align",
        "@boost.array",
        "@boost.asio",
        "@boost.assert",
        "@boost.bind",
        "@boost.charconv",
        "@boost.chrono",
        "@boost.compat",
        "@boost.config",
        "@boost.context",
        "@boost.core",
        "@boost.coroutine",
        "@boost.date_time",
        "@boost.endian",
        "@boost.exception",
        "@boost.function",
        "@boost.pfr",
        "@boost.regex",
        "@boost.smart_ptr",
        "@boost.system",
        "@boost.throw_exception",
        "@boost.type_traits",
        "@boost.utility",
    ] + select({
        ":openssl": [
            "@openssl//:crypto",
            "@openssl//:ssl",
        ],
        ":boringssl": [
            "@boringssl//:crypto",
            "@boringssl//:ssl",
        ],
        ":no_ssl": [],
    }),
)
